package com.zhw.task;

/**
 * 定义一个Executor接口的实现Task
 */
public class Task implements Executor {

    /**
     * 任务id
     */
    private Long id;
    /**
     * 任务名
     */
    private String name;
    /**
     * 任务状态，简化为0：未执行，1：已执行
     */
    private int state;

    public Task(Long id, String name, int state) {
        this.id = id;
        this.name = name;
        this.state = state;
    }

    @Override
    public boolean execute() {
        System.out.println("Task id: [" + id + "], " + "task name: [" + name +"] is running");
        state = 1;
        return true;
    }

    /**
     * 返回任务是否已执行
     */
    public boolean hasExecuted() {
        return state == 1;
    }

}
